package cn.tedu.tnt_sky.service.Impl;

import cn.tedu.tnt_sky.mapper.user.UserMapper;
import cn.tedu.tnt_sky.pojo.vo.UserMoonVO;
import cn.tedu.tnt_sky.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserMoonVO moonNumberUser() {
        //获取用户数量
        //查询用户创建时间中月份分为1-12的数量
        //计算用户增长效率
        UserMoonVO userMoonVO = new UserMoonVO();
        List<Integer> number = new ArrayList<>();
        List<Double> efficiency = new ArrayList<>();
        efficiency.add(0.0);
        Integer[] integers = new Integer[12];
        for (int moon = 0; moon < 12; moon++){
         integers[moon] = userMapper.queryUserNumberByMoon(moon+1);
         if (moon!=0){
             efficiency.add(((double)integers[moon]/(double)integers[moon-1]));
             integers[moon]=integers[moon]+ integers[moon -1];
         }
         number.add(integers[moon]);
        }
        userMoonVO.setNumber(number);
        userMoonVO.setEfficiency(efficiency);
        log.debug("每月人数数量为：{}",number);
        log.debug("增长效率为：{}",efficiency);
        // TODO 写完去填综合测评
        return userMoonVO;
    }
}
